package com.gxa.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.admin.entity.ShopApply;
import com.gxa.admin.entity.vo.ShopApplyVo;
import com.gxa.admin.group.Reg;
import com.gxa.admin.mapper.ShopApplyMapper;
import com.gxa.admin.param.ShopApplyParam;
import com.gxa.admin.service.ShopApplyService;
import com.gxa.admin.validator.MyValidator;
import com.gxa.o2o.core.dto.ResultDTO;
import com.gxa.o2o.core.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author 蔚枫
 * @version 1.0
 * Talk is cheap. Show me the code
 * @description
 * @date 2021/7/21 9:54
 */
@Service("shopApplyService")
public class ShopApplyServiceImpl implements ShopApplyService {

    @Autowired
    private MyValidator myValidator;

    @Autowired
    private ShopApplyMapper shopApplyMapper;

    @Override
    public ResultDTO queryById(Long shopApplyId) {
        ShopApply shopApply = shopApplyMapper.selectByPrimaryKey(shopApplyId);
        return Response.success(200, "success", shopApply);
    }

    @Override
    public List<ShopApply> queryAllByLimit(int offset, int limit) {
        return null;
    }

    @Override
    public ResultDTO insert(ShopApply shopApply) {
        return null;
    }

    /**
     * 审批
     * @param shopApplyVo 实例对象
     * @return
     */
    @Override
    public ResultDTO update(ShopApplyVo shopApplyVo) {
        myValidator.validate(shopApplyVo, Reg.class);
        shopApplyVo.setShopApplyAuditTime(new Timestamp(System.currentTimeMillis()));
        if (shopApplyMapper.updateByPrimaryKey(shopApplyVo)>0) {
            return Response.success(200, "修改成功！", shopApplyVo);
        }
        return Response.success(200, "修改失败");
    }

    @Override
    public ResultDTO deleteById(Long shopApplyId) {
        return null;
    }

    /**
     * 分页条件查询
     * @param shopApplyParam
     * @return
     */
    @Override
    public ResultDTO findByAll(ShopApplyParam shopApplyParam) {
        PageHelper.startPage(shopApplyParam.getPage(), shopApplyParam.getLimit());
        List<ShopApply> shopApplyList = shopApplyMapper.findByAll(shopApplyParam);
        shopApplyList.forEach(System.out::println);
        PageInfo<ShopApply> shopApplyPageInfo = new PageInfo<>(shopApplyList);
        System.out.println(shopApplyPageInfo.toString());
        return Response.success(200, "success", shopApplyPageInfo);
    }
}
